<template>
  <Dialog v-model="dialogVisible" title="下架过期资源" width="800" height="100">
    <el-table
      v-loading="loading"
      ref="refExpire"
      :data="list"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="id" label="ID" width="55" />
      <el-table-column prop="name" label="资源名称" />
      <el-table-column prop="type" label="资源类型" />
      <el-table-column prop="copyrightValidity" label="版权有效期" />
      <el-table-column prop="copyrightStatus" label="版权状态" />
    </el-table>
    <template #footer>
      <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script lang="ts" setup>
import * as microCopyrightApi from '@/api/copyright/microCopyright'

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const refExpire = ref() // 表单 Ref
const dialogVisible = ref(false) // 弹窗的是否展示
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  copyrightStatus: '已过期'
})
/** 多选 */
const multipleSelection = ref([])
const handleSelectionChange = (val: any) => {
  multipleSelection.value = val
}
/** 列表数据 */
const list = ref([])
/** 打开弹窗 */
const open = async () => {
  dialogVisible.value = true
  getList()
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await microCopyrightApi.getCopyrightExpire(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 提交按钮操作 */
const submitForm = async () => {
  if (multipleSelection.value.length == 0) {
    return message.error('请选择要下架的资源！')
  } else {
    return message.success(t('功能未开发！'))
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>
